/**
 *  按钮级别权限控制
 *  Copyright (c) 2021
 *  return  false  不可访问
 *          true   可访问
 */

const Permis = (value) => {
  // await setTimeout(function() {}, 1000);
  // 权限列表(从后台获取)
  let permissions = uni.getStorageSync("permissions");
  if (!permissions) {
    permissions = [];
  }
  // 匹配所有
  const all_permission = "*:*:*";

  // 参数是否传值
  if (value && value instanceof Array && value.length > 0) {
    const permissionFlag = value;
    const hasPermissions = permissions.some((permission) => {
      return (
        all_permission === permission || permissionFlag.includes(permission)
      );
    });

    if (!hasPermissions) {
      return false;
    } else {
      return true;
    }
  }
  return false;
};
export default Permis;
